$(function(){
	   easyloader.base = 'js/tools/easyui/';
	   using("locale/easyui-lang-zh_CN.js",function(){
	      var columns=[[
	                              {field: 'id',title: '标识',width: 80,align: 'center',hidden:true},
						          {field: 'username',title: '用户名',width: 80,align: 'center'},
								  {field: 'password',title: '密码',width: 120,align: 'center'},
						          {field: 'delete',title: '删除',width: 80,align: 'center',editor:'numberbox'}
							 ]];
	         createDateGrid(columns,'user!userList.action','',false,560);
	   });
	   $("#dialog").dialog();
});
//添加用户
function addUser()
{
	var username=$.trim($("#username").val());
	var password=$.trim($("#password").val());
	var password2=$.trim($("#password2").val());
	if(username.length<3||username.length>15)
	{
		alert("用户名在3~15之间！");
		return false;
	}
	if(password.length<6||password.length>30)
	{
		alert("密码在6~30之间！");
		return false;
	}else if(password!=password2)
	{
		alert("两次输入不一致！");
	    return false;
	}
	$.getJSON("user!findUser.action",{'user.username':username},function(data){
		if(data.info=="nologin")
		{
			 $.ajax({ url: 'admin/loginbox.html', 
			          cache: false, 
					   success:function(data){
			 	           $("body").append(data);
			           }
			 });
		}
		else if(!data.info)
		{
                $.getJSON("user!addUser.action",{'user.username':username,"user.password":password},function(data){
				    if(data.info)
					{
						 $("#dataGrid").datagrid("reload");
						alert("添加成功");
						$('#dialog').dialog('close');
					}else
					{
						alert("添加失败");
					}
				});
		}else
		{
			alert("用户名已经存在，请重新输入!");
		}
	});
}
//删除用户
function deleteUser(userId)
{
	$.getJSON("user!deleteUser.action",{"user.id":userId},function(data){
		       if(data.info)
					{
						$("#dataGrid").datagrid("reload");
						alert("删除成功");
					}else
					{
						alert("删除失败");
					}
	});
}
